﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:Panels="clr-namespace:ASPItalia.ModelVirtualCasting.Silverlight.Panels"
                    xmlns:Locals="clr-namespace:ASPItalia.ModelVirtualCasting.Silverlight"
                    xmlns:Toolkit="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Toolkit"
                    xmlns:System="clr-namespace:System;assembly=mscorlib">
    <ControlTemplate x:Key="ValidationToolTipTemplate">
        <Grid x:Name="Root"
              Margin="5,0"
              Opacity="0"
              RenderTransformOrigin="0,0">
            <Grid.RenderTransform>
                <TranslateTransform x:Name="xform"
                                    X="-25" />
            </Grid.RenderTransform>
            <VisualStateManager.VisualStateGroups>
                <VisualStateGroup x:Name="OpenStates">
                    <VisualStateGroup.Transitions>
                        <VisualTransition GeneratedDuration="0" />
                        <VisualTransition GeneratedDuration="0:0:0.2"
                                          To="Open">
                            <Storyboard>
                                <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="X"
                                                               Storyboard.TargetName="xform">
                                    <SplineDoubleKeyFrame KeyTime="0:0:0.2"
                                                          Value="0" />
                                </DoubleAnimationUsingKeyFrames>
                                <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="Opacity"
                                                               Storyboard.TargetName="Root">
                                    <SplineDoubleKeyFrame KeyTime="0:0:0.2"
                                                          Value="1" />
                                </DoubleAnimationUsingKeyFrames>
                            </Storyboard>
                        </VisualTransition>
                    </VisualStateGroup.Transitions>
                    <VisualState x:Name="Closed">
                        <Storyboard>
                            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="Opacity"
                                                           Storyboard.TargetName="Root">
                                <SplineDoubleKeyFrame KeyTime="0"
                                                      Value="0" />
                            </DoubleAnimationUsingKeyFrames>
                        </Storyboard>
                    </VisualState>
                    <VisualState x:Name="Open">
                        <Storyboard>
                            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="X"
                                                           Storyboard.TargetName="xform">
                                <SplineDoubleKeyFrame KeyTime="0"
                                                      Value="0" />
                            </DoubleAnimationUsingKeyFrames>
                            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="Opacity"
                                                           Storyboard.TargetName="Root">
                                <SplineDoubleKeyFrame KeyTime="0"
                                                      Value="1" />
                            </DoubleAnimationUsingKeyFrames>
                        </Storyboard>
                    </VisualState>
                </VisualStateGroup>
            </VisualStateManager.VisualStateGroups>
            <Border Background="#052A2E31"
                    CornerRadius="5"
                    Margin="4,4,-4,-4" />
            <Border Background="#152A2E31"
                    CornerRadius="4"
                    Margin="3,3,-3,-3" />
            <Border Background="#252A2E31"
                    CornerRadius="3"
                    Margin="2,2,-2,-2" />
            <Border Background="#352A2E31"
                    CornerRadius="2"
                    Margin="1,1,-1,-1" />
            <Border Background="#FFDC000C"
                    CornerRadius="2" />
            <Border CornerRadius="2">
                <TextBlock Foreground="White"
                           MaxWidth="250"
                           Margin="8,4,8,4"
                           TextWrapping="Wrap"
                           Text="{Binding (Validation.Errors)[0].ErrorContent}"
                           UseLayoutRounding="false" />
            </Border>
        </Grid>
    </ControlTemplate>
    <Style x:Key="ModelListBox"
           TargetType="ListBox">
        <Setter Property="Padding"
                Value="1" />
        <Setter Property="Foreground"
                Value="#FF000000" />

        <Setter Property="IsTabStop"
                Value="False" />
        <Setter Property="BorderThickness"
                Value="1" />
        <Setter Property="TabNavigation"
                Value="Once" />
        <Setter Property="ScrollViewer.HorizontalScrollBarVisibility"
                Value="Auto" />
        <Setter Property="ScrollViewer.VerticalScrollBarVisibility"
                Value="Auto" />
        <Setter Property="BorderBrush"
                Value="{x:Null}" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="ListBox">
                    <Grid Background="Transparent">
                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup x:Name="ValidationStates">
                                <VisualState x:Name="Valid" />
                                <VisualState x:Name="InvalidUnfocused">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Visibility"
                                                                       Storyboard.TargetName="ValidationErrorElement">
                                            <DiscreteObjectKeyFrame KeyTime="0">
                                                <DiscreteObjectKeyFrame.Value>
                                                    <Visibility>Visible</Visibility>
                                                </DiscreteObjectKeyFrame.Value>
                                            </DiscreteObjectKeyFrame>
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="InvalidFocused">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Visibility"
                                                                       Storyboard.TargetName="ValidationErrorElement">
                                            <DiscreteObjectKeyFrame KeyTime="0">
                                                <DiscreteObjectKeyFrame.Value>
                                                    <Visibility>Visible</Visibility>
                                                </DiscreteObjectKeyFrame.Value>
                                            </DiscreteObjectKeyFrame>
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="IsOpen"
                                                                       Storyboard.TargetName="validationTooltip">
                                            <DiscreteObjectKeyFrame KeyTime="0">
                                                <DiscreteObjectKeyFrame.Value>
                                                    <System:Boolean>True</System:Boolean>
                                                </DiscreteObjectKeyFrame.Value>
                                            </DiscreteObjectKeyFrame>
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>
                        <Border BorderBrush="{TemplateBinding BorderBrush}"
                                BorderThickness="{TemplateBinding BorderThickness}"
                                CornerRadius="2">
                            <ItemsPresenter />
                        </Border>
                        <Border x:Name="ValidationErrorElement"
                                BorderBrush="#FFDB000C"
                                BorderThickness="{TemplateBinding BorderThickness}"
                                CornerRadius="2"
                                Visibility="Collapsed">
                            <ToolTipService.ToolTip>
                                <ToolTip x:Name="validationTooltip"
                                         DataContext="{Binding RelativeSource={RelativeSource TemplatedParent}}"
                                         Placement="Right"
                                         PlacementTarget="{Binding RelativeSource={RelativeSource TemplatedParent}}"
                                         Template="{StaticResource ValidationToolTipTemplate}">
                                    <ToolTip.Triggers>
                                        <EventTrigger RoutedEvent="Canvas.Loaded">
                                            <BeginStoryboard>
                                                <Storyboard>
                                                    <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="IsHitTestVisible"
                                                                                   Storyboard.TargetName="validationTooltip">
                                                        <DiscreteObjectKeyFrame KeyTime="0">
                                                            <DiscreteObjectKeyFrame.Value>
                                                                <System:Boolean>true</System:Boolean>
                                                            </DiscreteObjectKeyFrame.Value>
                                                        </DiscreteObjectKeyFrame>
                                                    </ObjectAnimationUsingKeyFrames>
                                                </Storyboard>
                                            </BeginStoryboard>
                                        </EventTrigger>
                                    </ToolTip.Triggers>
                                </ToolTip>
                            </ToolTipService.ToolTip>
                            <Grid Background="Transparent"
                                  HorizontalAlignment="Right"
                                  Height="10"
                                  Margin="0,-4,-4,0"
                                  VerticalAlignment="Top"
                                  Width="10">
                                <Path Data="M 1,0 L6,0 A 2,2 90 0 1 8,2 L8,7 z"
                                      Fill="#FFDC000C"
                                      Margin="-1,3,0,0" />
                                <Path Data="M 0,0 L2,0 L 8,6 L8,8"
                                      Fill="#ffffff"
                                      Margin="-1,3,0,0" />
                            </Grid>
                        </Border>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        <Setter Property="Background"
                Value="Transparent" />
        <Setter Property="Margin"
                Value="40,0,0,50" />
    </Style>
    <Style x:Key="SelectedModelListBox"
           TargetType="ListBox">
        <Setter Property="Padding"
                Value="1" />
        <Setter Property="Foreground"
                Value="#FF000000" />
        <Setter Property="HorizontalContentAlignment"
                Value="Left" />
        <Setter Property="VerticalContentAlignment"
                Value="Top" />
        <Setter Property="IsTabStop"
                Value="False" />
        <Setter Property="BorderThickness"
                Value="1" />
        <Setter Property="TabNavigation"
                Value="Once" />
        <Setter Property="ScrollViewer.HorizontalScrollBarVisibility"
                Value="Auto" />
        <Setter Property="ScrollViewer.VerticalScrollBarVisibility"
                Value="Auto" />
        <Setter Property="BorderBrush"
                Value="{x:Null}" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="ListBox">
                    <Grid>
                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup x:Name="ValidationStates">
                                <VisualState x:Name="Valid" />
                                <VisualState x:Name="InvalidUnfocused">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Visibility"
                                                                       Storyboard.TargetName="ValidationErrorElement">
                                            <DiscreteObjectKeyFrame KeyTime="0">
                                                <DiscreteObjectKeyFrame.Value>
                                                    <Visibility>Visible</Visibility>
                                                </DiscreteObjectKeyFrame.Value>
                                            </DiscreteObjectKeyFrame>
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="InvalidFocused">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Visibility"
                                                                       Storyboard.TargetName="ValidationErrorElement">
                                            <DiscreteObjectKeyFrame KeyTime="0">
                                                <DiscreteObjectKeyFrame.Value>
                                                    <Visibility>Visible</Visibility>
                                                </DiscreteObjectKeyFrame.Value>
                                            </DiscreteObjectKeyFrame>
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="IsOpen"
                                                                       Storyboard.TargetName="validationTooltip">
                                            <DiscreteObjectKeyFrame KeyTime="0">
                                                <DiscreteObjectKeyFrame.Value>
                                                    <System:Boolean>True</System:Boolean>
                                                </DiscreteObjectKeyFrame.Value>
                                            </DiscreteObjectKeyFrame>
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>
                        <Border BorderBrush="{TemplateBinding BorderBrush}"
                                BorderThickness="{TemplateBinding BorderThickness}"
                                CornerRadius="2">
                            <ScrollViewer x:Name="ScrollViewer"
                                          BorderBrush="Transparent"
                                          BorderThickness="0"
                                          Background="{TemplateBinding Background}"
                                          Padding="{TemplateBinding Padding}"
                                          TabNavigation="{TemplateBinding TabNavigation}"
                                          Style="{StaticResource ScrollViewerStyle1}">
                                <ItemsPresenter />
                            </ScrollViewer>
                        </Border>
                        <Border x:Name="ValidationErrorElement"
                                BorderBrush="#FFDB000C"
                                BorderThickness="{TemplateBinding BorderThickness}"
                                CornerRadius="2"
                                Visibility="Collapsed">
                            <ToolTipService.ToolTip>
                                <ToolTip x:Name="validationTooltip"
                                         DataContext="{Binding RelativeSource={RelativeSource TemplatedParent}}"
                                         Placement="Right"
                                         PlacementTarget="{Binding RelativeSource={RelativeSource TemplatedParent}}"
                                         Template="{StaticResource ValidationToolTipTemplate}">
                                    <ToolTip.Triggers>
                                        <EventTrigger RoutedEvent="Canvas.Loaded">
                                            <BeginStoryboard>
                                                <Storyboard>
                                                    <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="IsHitTestVisible"
                                                                                   Storyboard.TargetName="validationTooltip">
                                                        <DiscreteObjectKeyFrame KeyTime="0">
                                                            <DiscreteObjectKeyFrame.Value>
                                                                <System:Boolean>true</System:Boolean>
                                                            </DiscreteObjectKeyFrame.Value>
                                                        </DiscreteObjectKeyFrame>
                                                    </ObjectAnimationUsingKeyFrames>
                                                </Storyboard>
                                            </BeginStoryboard>
                                        </EventTrigger>
                                    </ToolTip.Triggers>
                                </ToolTip>
                            </ToolTipService.ToolTip>
                            <Grid Background="Transparent"
                                  HorizontalAlignment="Right"
                                  Height="10"
                                  Margin="0,-4,-4,0"
                                  VerticalAlignment="Top"
                                  Width="10">
                                <Path Data="M 1,0 L6,0 A 2,2 90 0 1 8,2 L8,7 z"
                                      Fill="#FFDC000C"
                                      Margin="-1,3,0,0" />
                                <Path Data="M 0,0 L2,0 L 8,6 L8,8"
                                      Fill="#ffffff"
                                      Margin="-1,3,0,0" />
                            </Grid>
                        </Border>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        <Setter Property="Background"
                Value="Transparent" />
        <Setter Property="Width"
                Value="400" />
        <Setter Property="Height"
                Value="250" />
        <Setter Property="HorizontalAlignment"
                Value="Left" />
        <Setter Property="VerticalAlignment"
                Value="Bottom" />
    </Style>
    <ItemsPanelTemplate x:Key="ModelsItemsPanelTemplate">
        <Panels:Panel3D />
    </ItemsPanelTemplate>
    <DataTemplate x:Key="FakeModelsItemTemplate" >
        <Border Padding="10" 
                Width="165">
            <Border.Effect>
                <DropShadowEffect ShadowDepth="3"
                                  Opacity="0.4"
                                  BlurRadius="10" />
            </Border.Effect>
            <Border.Background>
                <LinearGradientBrush EndPoint="0.5,1"
                                     StartPoint="0.5,0">
                    <GradientStop Color="#FF8B8686"
                                  Offset="1" />
                    <GradientStop Color="White"
                                  Offset="0.916" />
                </LinearGradientBrush>
            </Border.Background>
            <StackPanel>
                <Image Source="{Binding Multimedia, Converter={StaticResource FirstImageConverter}}"
                       Height="230"
                       Stretch="UniformToFill" />
                <TextBlock Text="{Binding FirstName, StringFormat='Nome: {0}'}"
                           TextTrimming="WordEllipsis"
                            Margin="0,5,0,0"/>
                <TextBlock Text="{Binding LastName,  StringFormat='Cognome: {0}'}"
                           TextTrimming="WordEllipsis"
                           Margin="0,5,0,0" />
            </StackPanel>
        </Border>
    </DataTemplate>
    <DataTemplate x:Key="SelectedModelItemtemplate">
        <Border Padding="5"
                Width="80">
            <Border.Effect>
                <DropShadowEffect ShadowDepth="6"
                                  Opacity="0.24"
                                  BlurRadius="6" />
            </Border.Effect>
            <Border.Background>
                <LinearGradientBrush EndPoint="0.5,1"
                                     StartPoint="0.5,0">
                    <GradientStop Color="#FF8B8686"
                                  Offset="1" />
                    <GradientStop Color="White"
                                  Offset="0.916" />
                </LinearGradientBrush>
            </Border.Background>
            <StackPanel>
                <Image Source="{Binding Multimedia, Converter={StaticResource FirstImageConverter}}"
                       Height="80"
                       Width="70"
                       Stretch="UniformToFill" />
                <TextBlock Text="{Binding FirstName,StringFormat='N: {0}'}"
                           TextTrimming="WordEllipsis"
                           Margin="0,2,0,0" />
                <TextBlock Text="{Binding LastName,StringFormat='C: {0}'}"
                           TextTrimming="WordEllipsis"
                           Margin="0,2,0,0" />

            </StackPanel>
        </Border>
    </DataTemplate>
  </ResourceDictionary>